#!/bin/bash
# -*- coding: utf-8 -*-
# RAG智能问答系统 - 前端服务启动脚本（Linux版本）
# 使用方法：chmod +x 启动前端服务.sh && ./启动前端服务.sh

echo "========================================"
echo "RAG智能问答系统 - 前端服务启动脚本"
echo "========================================"
echo ""

echo "[1/3] 检查依赖包..."
if python3 -c "import flask" 2>/dev/null; then
    echo "✅ 依赖包已安装"
else
    echo "❌ Flask未安装，正在安装依赖..."
    pip3 install flask flask-cors openai python-dotenv -q
    if [ $? -ne 0 ]; then
        echo "❌ 依赖安装失败，请手动运行: pip3 install -r requirements.txt"
        read -p "按回车键退出..."
        exit 1
    fi
    echo "✅ 依赖安装完成"
fi

echo ""
echo "[2/3] 检查向量数据库..."
if [ ! -d "chroma_db" ]; then
    echo "⚠️  向量数据库不存在"
    echo "   请先运行: python3 rag_document_ingestion.py"
    echo ""
    read -p "是否继续启动服务？(y/n): " choice
    if [ "$choice" != "y" ] && [ "$choice" != "Y" ]; then
        echo "已取消启动"
        exit 1
    fi
else
    echo "✅ 向量数据库已就绪"
fi

echo ""
echo "[3/3] 启动Flask服务..."
echo ""
echo "========================================"
echo "🚀 服务正在启动..."
echo "📡 访问地址: http://localhost:5000"
echo "💡 按 Ctrl+C 停止服务"
echo "========================================"
echo ""

# 启动应用
python3 app.py

# 脚本结束后提示
echo ""
echo "========================================"
echo "服务已停止"
echo "========================================"


